When you specify a subexpression with parentheses, the text that matches the subexpression (that is, what this grouping captures) can be further processed in an expression or other program.By default, each grouping automatically has a group number,
ProblemI saw a blog post yesterday, and I talked about a Java interview question:
Given a string, if the middle of the string contains "*", the "*" is deleted, and if the string first or last character is "*", the "*" is preserved.
Give
Nameless, well-known group (1) Regular expression-nameless groupStarting from the left side of the regular expression, the first opening parenthesis "(" represents the first grouping, the second represents the second grouping, and so on.It is
Back reference
One of the most important features of regular expressions is the ability to store portions of a successful pattern for later use. Recall that adding parentheses around a regular expression pattern or part of a pattern causes this part
Microsoft | regular back Reference
One of the most important features of regular expressions is the ability to store portions of a successful pattern for later use. Recall that adding parentheses around a regular expression pattern or part of a
Back reference
One of the most important features of regular expressions is the ability to store portions of a successful pattern for later use. Recall that adding parentheses around a regular expression pattern or part of a pattern causes this part
-- Start
InBrackets and backward referencesThe section describes two uses of parentheses: grouping and capturing.Group
In fact, the regular expression also provides three types of structures for grouping:
Note
Comments are provided in any programming language. otherwise, many codes are not easy to understand. if the regular expression contains thousands of rows without comments, it is hard for you to see vomiting.
The format of the comment is (? #
Backward reference
One of the most important features of a regular expression is to store a part of the matched pattern for future use. Recall that adding parentheses on both sides of a regular expression mode or partial mode will cause this
The method is very simple, that is, using the IndexOf function of JS. Separate and = to be divided, so that we can save the data we want to an array, so that the operation can be convenient, this article only for reference to the needs of friends
Outside a character class, a backslash immediately follows a number that is greater than 0 (and possibly one number) is a back reference to a capturing group that occurred before the pattern.
If the number that follows the backslash is less than 10,
preg_replace- Perform a search and replace of a regular expressionDescriptionmixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit =-1 [, int &$count ]] )The subject matching portion of the search pattern to
A very important way of handling strings in PHP is regular expressions, which is also a method in other languages, because regular expressions are really too powerful for string processing, so here's a summary, remember the first time I touched PHP,
This article to the students about the Preg_replace () parameters are several multiple substitution of some self-understanding and replacement number of solutions, there is a need to understand the same non-reference.
Mixed preg_replace (mixed
Regular Expression SyntaxIn a typical search and replace operation, you must provide the exact text you want to find. This technique may suffice for simple search and replace tasks in static text, but because of its lack of flexibility, it can be
Regular expression syntaxA regular expression is a text pattern consisting of ordinary characters, such as characters A through z, and special characters (called metacharacters ). This pattern describes one or more strings to match when looking up a
The use of regular expressions is detailedBrief introductionSimply put, regular expressions are a powerful tool that can be used for pattern matching and substitution. The function is as follows:Tests a pattern for a string. For example, you can
Subgroups are delimited by parentheses, and they can be nested. To mark a part of a pattern as a subgroup (sub-mode) The main thing is to do two things:
Localization of optional branches. For example, Mode Cat (arcat|erpillar|) Match "Cat",
Character
Describe
\
The next character is marked with a special character, or a literal character, or a back reference, or an octal escape character. For example, ' n ' matches the character "n". ' \ n ' matches a line break.
1. preg_match-performs a regular expression matchint Preg_match (string $pattern, String $subject [, Array & $matches [, int $flags = 0 [, int $offset = 0]])
Searches for a match between the subject and the regular expression given by the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.